using Microsoft.Data.Entity.Storage;
using CS.CleverNotes.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Framework.DependencyInjection;
using System.IO;

namespace CS.CleverNotes.Infrastructure
{
    public static class DbInitializer
    {
        private static CleverNotesContext context;
        public static void Initialize(IServiceProvider serviceProvider, string imagesPath)
        {
            context = (CleverNotesContext)serviceProvider.GetService<CleverNotesContext>();

            InitializeProjects();
            InitializeUserRoles();
        }

        private static void InitializeProjects()
        {
            context.Database.EnsureCreated();

            #region Todos

            if (!context.ToDo.Any())
            {
                var cat1 = context.ToDo.Add(
                    new Todo
                    {
                        DateCreated = DateTime.Now,
                        SortOrder = 1,
                        Title = "Family",
                        Completed = false
                    }).Entity;
                context.SaveChanges();

                var cat2 = context.ToDo.Add(
                   new Todo
                   {
                       DateCreated = DateTime.Now,
                       Title = "House",
                       SortOrder = 2,
                       Completed = false
                   }).Entity;
                context.SaveChanges();

                var cat3 = context.ToDo.Add(
                   new Todo
                   {
                       DateCreated = DateTime.Now,
                       SortOrder = 3,
                       Title = "Projects",
                       Completed = false
                   }).Entity;
                context.SaveChanges();

                var cat5 = context.ToDo.Add(
                  new Todo
                  {
                      DateCreated = DateTime.Now,
                      SortOrder = 0,
                      Title = "Car",
                      Completed = false
                  }).Entity;
                context.SaveChanges();

                var cat6 = context.ToDo.Add(
                   new Todo
                   {
                       DateCreated = DateTime.Now,
                       SortOrder = 0,
                       Title = "Common",
                       Completed = false
                   }).Entity;
                context.SaveChanges();

                context.ToDo.AddRange(new []{
                    new Todo
                    {
                        DateCreated = DateTime.Now,
                        Title = "https://material.angularjs.org/latest/demo/chips",
                        ParentId = cat1.Id,
                        Completed = false
                    },
                    new Todo
                    {
                        DateCreated = DateTime.Now,
                        Title = "Some example Task",
                        ParentId = cat2.Id,
                        Completed = false
                    }});
                context.SaveChanges();
            }
            #endregion
        }

        private static void InitializeUserRoles()
        {
      
        }
    }
}
